import { _decorator, Component, log, Node, tween, Vec3 } from 'cc';
import { GameManager } from './GameManager';
import { AudioManager } from './AudioManager';
const { ccclass, property } = _decorator;

@ccclass('PlayerManager')
export class PlayerManager extends Component {

    private isTweening: boolean = false; // 核心：一个简单的标志位

    start() {
     
    }
    //跳起来
    jump(num:number) {
        console.log("jump",num,this.isTweening);
        if(this.isTweening) return;
        this.isTweening = true;
        AudioManager.instance.playSFX('sound/boom', false);
        // tween()
        // .target(node)
        // .by(0.3, { position: new Vec3(80*num, 100, 0) })
        // .delay(0.05)
        // .by(0.2, { position: new Vec3(0, -100, 0) })
        // .call(() => {
        //     this.isTweening = false;
        //     GameManager.instance.jumpEnd();
        // })
        // .start()
        let node = this.node.getChildByName("main");
        tween(this.node).parallel(
                tween(node)
                        .by(0.3, { position: new Vec3(0, 100, 0) })
                        .delay(0.05)
                        .by(0.2, { position: new Vec3(0, -100, 0) }),
                tween(this.node)
                        .by(0.3, { position: new Vec3(80*num, 0, 0) }),
                
            ).call(() => {
                this.isTweening = false;
                GameManager.instance.jumpEnd(num);
            })
            .start();

    }

    update(deltaTime: number) {
    }
}


